﻿// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the TRANSLATOR_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// TRANSLATOR_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.

#include <souicoll.h>
#include <unknown/obj-ref-impl.hpp>
#include <string/tstring.h>
#include <string/strcpcvt.h>
#include <pugixml/pugixml.hpp>
#include <interface/STranslator-i.h>
#include <map>
namespace SOUI {
    class SStrMap;
    class SStrMapEntry;
    
    enum LANGDATA {
        LD_UNKNOWN = 0,
        LD_XML,
        LD_COMPILEDFILE,
        LD_COMPILEDDATA,
        LD_BUFFER,
    };
    
    struct TrFontInfo {
        BYTE lfCharset;
        SStringT strFaceName;
    };
    
    
    class STranslator : public TObjRefImpl<ITranslator> {
        friend class STranslatorMgr;
        
      public:
        STranslator();
        ~STranslator();
        
        virtual BOOL Load(LPVOID pData, UINT uType);
        virtual BOOL LoadFromBuffer(const SStringW &name, LPVOID pData, UINT size);
        virtual void GetName(wchar_t szName[TR_MAX_NAME_LEN]);
        virtual bool NameEqual(LPCWSTR pszName);
        
        virtual SStringW     guid();
        virtual int tr(const SStringW &strSrc, const SStringW &strCtx, wchar_t *pszOut, int nBufLen) const ;
        virtual SStringW getFontInfo() const;
        
      protected:
        BOOL LoadFromXml(pugi::xml_node xmlLang);
        
        wchar_t         m_szLangName[TR_MAX_NAME_LEN];
        SStringW        m_guid;
        SArray<SStrMapEntry *> *m_arrEntry;
        SStringW        m_strFontInfo;
    };
    
    class STranslatorMgr : public TObjRefImpl<ITranslatorMgr> {
      public:
        STranslatorMgr(void);
        ~STranslatorMgr(void);
        
        virtual void SetLanguage(const SStringW &strLang);
        virtual void GetLanguage(wchar_t szName[TR_MAX_NAME_LEN]) const;
        
        BOOL CreateTranslator(ITranslator **ppTranslator);
        
        BOOL InstallTranslator(ITranslator *pTranslator);
        
        BOOL UninstallTranslator(const SStringW &id);
        
        int tr(const SStringW &strSrc, const SStringW &strCtx, wchar_t *pBuf, int nLen)  const ;
        
      protected:
        wchar_t  m_szLangName[TR_MAX_NAME_LEN];
        SList<ITranslator *> *m_lstLang;
    };
    
    namespace TRANSLATOR {
        SOUI_COM_C BOOL SOUI_COM_API SCreateInstanceTrantor(IObjRef **ppTrans);
    }
    
}
